<?php if(!isset($_SESSION)){
  session_start();
}
require_once('../../Connections/microassur.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
$vide= !empty($_POST["Code_banque_rib"]) && !empty($_POST["Code_guichet_rib"]) && !empty($_POST["Numero_compte_rib"]) && !empty($_POST["Cle_rib"]) ;


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && $bool && $vide)
$bool= verifLibelle1("Code_banque_rib") && verifLibelle1("Code_guichet_rib") && verifLibelle1("Numero_compte_rib") && verifLibelle1("Cle_rib") ;;

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO rib (Identifiant_rib, Code_banque_rib, Code_guichet_rib, Numero_compte_rib, Cle_rib, Etat_rib, Identifiant_personne) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Identifiant_rib'], "int"),
                       GetSQLValueString($_POST['Code_banque_rib'], "text"),
                       GetSQLValueString($_POST['Code_guichet_rib'], "text"),
                       GetSQLValueString($_POST['Numero_compte_rib'], "text"),
                       GetSQLValueString($_POST['Cle_rib'], "text"),
                       GetSQLValueString("A", "text"),
                       GetSQLValueString($_SESSION['idpers'], "int"));

  mysql_select_db($database_microassur, $microassur);
  $Result1 = mysql_query($insertSQL, $microassur) or die(mysql_error());
  if(!$Result1)$message.="<br>Problème création RIB, contacter la DSI ";
  else
  {
  header("location:rattacher.php?");
  $req=mysql_query("select max(Identifiant_rib)  as idrib from rib")or die(mysql_error());
	  if($req)
		{
			$rep=mysql_fetch_array($req);
			$idrib=$rep['idrib'];
			header("location : rattacherrib.php?Identifiant_rib=".$idrib);
		}
  }
}
elseif((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && !$vide)
{
if(empty($_POST["Code_banque_rib"]))$message=colorer("Vous devez saisir le code banque ","false");
elseif(empty($_POST["Code_guichet_rib"]))$message=colorer("Vous devez saisir le code guichet ","false");
elseif(empty($_POST["Numero_compte_rib"]))$message=colorer(" 	Vous devez saisir le numéro de compte ","false");
elseif(empty($_POST["Cle_rib"]))$message=colorer("Vous devez saisir la clé ","false");

}
elseif((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1") && !$bool)
{
 if(!verifLibelle1("Code_banque_rib"))$message=colorer("Le code banque saisi comporte des caractères spéciaux interdits ","false");
  if(!verifLibelle1("Code_guichet_rib"))$message=colorer("Le code guichet saisi comporte des caractères spéciaux interdits ","false");
 if(!verifLibelle1("Numero_compte_rib"))$message=colorer("Le numéro de compte saisi comporte des caractères spéciaux ","false");
 if(!verifLibelle1("Cle_rib"))$message=colorer("La clé RIB saisie comporte des caractères spéciaux ","false");

}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">CODE BANQUE:</td>
      <td><input type="text" name="Code_banque_rib" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">GUICHET</td>
      <td><input type="text" name="Code_guichet_rib" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">NUMERO DE COMPTE</td>
      <td><input type="text" name="Numero_compte_rib" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">CLE RIB</td>
      <td><input type="text" name="Cle_rib" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Valider" />
        <a href="index.php">Retour</a></td>
    </tr>
  </table>
  <input type="hidden" name="Identifiant_rib" value="" />
  <input type="hidden" name="Etat_rib" value="" />
  <input type="hidden" name="Identifiant_personne" value="" />
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
